import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
//引入路径模块
import path from 'path'

// https://vitejs.dev/config/
export default defineConfig({
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "src"),
      'vue': 'vue/dist/vue.esm-bundler.js' // 定义vue的别名，如果使用其他的插件，可能会用到别名
      // "styles": path.resolve(__dirname, "src/styles"),
      // "plugins": path.resolve(__dirname, "src/plugins"),
      // "views": path.resolve(__dirname, "src/views"),
      // "layouts": path.resolve(__dirname, "src/layouts"),
      // "utils": path.resolve(__dirname, "src/utils"),
      // "apis": path.resolve(__dirname, "src/apis"),
      // "dirs": path.resolve(__dirname, "src/directives"),
    },
  },
  server: {
    //proxy解决跨域
    proxy: {
      '/shop': {
        target: 'http://www.thinkphp.com/shop',
        // target: 'https://thinkphp.lijingji.top/shop',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/shop/, ''),
      },
    }
  },
  //导入插件
  plugins: [
    vue(),
    AutoImport({
      imports: [
        'vue',
        // router的函数都能用了，把vue-router理解为python的一个包就行了
        'vue-router',
        {
          // 默认导入vant的弹窗
          'vant': [
            ['showConfirmDialog'],['showSuccessToast', 'success'],['showFailToast', 'error'] //success是别名
          ],
          '@/api/index.js': [
            ['default', 'Api']
          ],
          // 'axios': [  //导入其他包的格式，相当于提前放import { default as axios } from 'axios',
          //   // default imports
          //   ['default', 'axios'],
          // ],
        }
      ]
    }),
  ],
})